#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int romanToInt(char* s)
{
    int sum = 0;
    int flag = 1;
    while (*s)
    {
        while (1)
        {
            if (*s == 'M')
            {
                sum += 1000;
                s++;
                break;
            }
            if (*s == 'D')
            {
                sum += 500;
                s++;
                break;
            }
            if (*s == 'C' && *(s + 1) != 0 && *(s + 1) != 'L' && *(s + 1) != 'X' && *(s + 1) != 'V' && *(s + 1) != 'I'&& *(s + 1) != 'C')
            {
                sum -= 100;
                while (*(s + 1) != 'D'&& *(s + 1) != 'M')
                {
                    sum -= 100;
                    s++;
                    flag = 0;
                }
                if (flag)
                {
                    s++;
                }
                break;
            }
            else if (*s == 'C')
            {
                sum += 100;
                s++;
                break;
            }
            if (*s == 'L')
            {
                sum += 50;
                s++;
                break;
            }
            if (*s == 'X' && *(s + 1) != 0 && *(s + 1) != 'I' && *(s + 1) != 'V' && *(s + 1) != 'I'&& *(s + 1) != 'X')
            {
                sum -= 10;
                while (*(s + 1) != 'C' && *(s + 1) != 'L')
                {
                    sum -= 10;
                    s++;
                    flag = 0;
                }
                if (flag)
                {
                    s++;
                }
                break;
            }
            else if (*s == 'X')
            {
                sum += 10;
                s++;
                break;

            }
            if (*s == 'V')
            {
                sum += 5;
                s++;
                break;
            }
            if (*s == 'I' && *(s + 1) != 0 && *(s + 1) != 'I')
            {
                sum -= 1;
                while (*(s + 1) != 'V' && *(s + 1) != 'X')
                {
                    sum -= 1;
                    s++;
                    flag = 0;
                }
                if (flag)
                {
                    s++;
                }
                break;
            }
            else if (*s == 'I')
            {
                sum += 1;
                s++;
                break;
            }
        }
    }
    return sum;
}
int main()
{
    char str[20] = "DCXXI";
    printf("%d", romanToInt(str));
    return 0;
}